package com.tianya.portal.blog.service.impl;

import com.tianya.common.web.utils.StringUtils;
import com.tianya.portal.blog.mapper.BlogBookRecallMapper;
import com.tianya.portal.blog.service.IBlogBookRecallService;
import com.tianya.portal.system.domain.SysFile;
import com.tianya.portal.system.mapper.SysFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tianya.portal.blog.domain.BlogBookRecall;

import java.util.List;

/**
 * 文学记录 服务层实现
 *
 * @author tianya
 * @date 2024-06-10
 */
@Service
public class BlogBookRecallServiceImpl implements IBlogBookRecallService {
    @Autowired
    private BlogBookRecallMapper blogBookRecallMapper;

    @Autowired
    private SysFileMapper sysFileMapper;

    /**
     * 查询文学记录信息
     *
     * @param id 文学记录ID
     * @return 文学记录信息
     */
    @Override
    public BlogBookRecall selectBlogBookRecallById(String id) {
        blogBookRecallMapper.updateViewNumber(id);
        BlogBookRecall bookRecall = blogBookRecallMapper.selectBlogBookRecallById(id);
        if (StringUtils.isNotEmpty(bookRecall.getImageId())) {
            SysFile sysFile = sysFileMapper.selectSysFileById(bookRecall.getImageId());
            bookRecall.setSysFile(sysFile);
        }
        return bookRecall;
    }

    /**
     * 查询文学记录列表
     *
     * @param blogBookRecall 文学记录信息
     * @return 文学记录集合
     */
    @Override
    public List<BlogBookRecall> selectBlogBookRecallList(BlogBookRecall blogBookRecall) {
        List<BlogBookRecall> bookRecallList = blogBookRecallMapper.selectBlogBookRecallList(blogBookRecall);
        for (BlogBookRecall bookRecall : bookRecallList) {
            if (StringUtils.isNotEmpty(bookRecall.getImageId())) {
                SysFile sysFile = sysFileMapper.selectSysFileById(bookRecall.getImageId());
                bookRecall.setSysFile(sysFile);
            }
        }
        return bookRecallList;
    }
}
